using MicroMsg.Common.Utils;
using MicroMsg.Plugin.QQInfo.Manager;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Util;
using System;
using System.Collections.Generic;
using System.Xml.Linq;
namespace MicroMsg.Manager
{
	public static class ContactHelper
	{
		public enum emMMUserAttrVerifyFlag
		{
			MM_USERATTRVERIFYFALG_BIZ = 1,
			MM_USERATTRVERIFYFALG_FAMOUS,
			MM_USERATTRVERIFYFALG_BIZ_BIG = 4,
			MM_USERATTRVERIFYFALG_BIZ_BRAND = 8,
			MM_USERATTRVERIFYFALG_BIZ_VERIFIED = 16
		}
		private const string TAG = "ContactHelper";
		public const string cStrFileHelper = "filehelper";
		public const string SPUSER_WEIBO = "weibo";
		public const string SPUSER_QQMAIL = "qqmail";
		public const string SPUSER_FMESSAGE = "fmessage";
		public const string SPUSER_TMESSAGE = "tmessage";
		public const string SPUSER_QMESSAGE = "qmessage";
		public const string SPUSER_QQSYNC = "qqsync";
		public const string SPUSER_BOTTLE = "floatbottle";
		public const string SPUSER_LBS = "lbsapp";
		public const string SPUSER_SHAKE = "shakeapp";
		public const string WEIXINTWNAME = "微信團隊";
		public const string cStrWeixinTeam = "weixin";
		public const string cStrGroupCardHeader = "groupCardHeader@groupCardHeader";
		public const string cStrGroupUsrNameSuffix = "@chatroom";
		public static string[] HELPER = new string[]
		{
			"qqmail",
			"fmessage",
			"tmessage",
			"qmessage",
			"qqsync",
			"floatbottle",
			"lbsapp",
			"shakeapp"
		};
		public static string[] HELPERTWNAME = new string[]
		{
			"QQ郵箱提醒",
			"好友推薦讯息",
			"私信助手",
			"QQ離線助手",
			"通訊錄安全助手",
			"漂流瓶",
			"查看附近的人",
			"搖一搖"
		};
		public static List<BrandUser> getBrandList(this Contact contact_0)
		{
			return BrandUser.fromXml(contact_0.strMyBrandList);
		}
		public static void updateBrand(this Contact contact_0, BrandUser brandUser)
		{
			List<BrandUser> list = BrandUser.fromXml(contact_0.strMyBrandList);
			if (list == null)
			{
				return;
			}
			int num = 0;
			using (List<BrandUser>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					BrandUser current = enumerator.get_Current();
					if (brandUser.strUsrName == current.strUsrName)
					{
						list.set_Item(num, brandUser);
						contact_0.strMyBrandList = BrandUser.toXml(list);
						return;
					}
					num++;
				}
			}
			list.Add(brandUser);
			contact_0.strMyBrandList = BrandUser.toXml(list);
		}
		public static void setBrandList(this Contact contact_0, List<BrandUser> userList)
		{
			contact_0.strMyBrandList = BrandUser.toXml(userList);
		}
		public static bool isQQMailHelper(string username)
		{
			return username != null && username.Equals("qqmail", 1);
		}
		public static bool isFriendsRecommendHelper(string username)
		{
			return username != null && username.Equals("fmessage", 1);
		}
		public static bool isMicroBlogPrivateMsgHelper(string username)
		{
			return username != null && username.Equals("tmessage", 1);
		}
		public static bool isFloatBottleHelper(string username)
		{
			return username != null && username.Equals("floatbottle", 1);
		}
		public static bool isQQOffLineMessageHelper(string username)
		{
			return username != null && username.Equals("qmessage", 1);
		}
		public static bool isQQSyncHelper(string username)
		{
			return "qqsync".Equals(username, 1);
		}
		public static bool isTContact(string username)
		{
			return username != null && username.EndsWith(ConstantValue.TAG_MICROBLOG_TENCENT);
		}
		public static bool isQContact(string username)
		{
			return username != null && username.EndsWith(ConstantValue.TAG_QQ);
		}
		public static bool isNewsContact(string username)
		{
			return !string.IsNullOrEmpty(username) && (username.Equals(ConstantValue.TAG_NEWS) || username == ConstantValue.TAG_NEWS);
		}
		public static bool isQQMailContact(string username)
		{
			return username != null && username.Equals(ConstantValue.TAG_QQMAIL);
		}
		public static bool isBlogAppContact(string username)
		{
			return username != null && username.Equals(ConstantValue.TAG_BLOGAPP);
		}
		public static bool isBottleContact(string username)
		{
			return username != null && (username.Contains(ConstantValue.TAG_BOTTLE + ":") || username.Contains(ConstantValue.TAG_BOTTLE));
		}
		public static string getDisplayName(string strUserName, string strOptionalNickName)
		{
			Contact contact = StorageMgr.contact.method_0(strUserName);
			if (contact != null)
			{
				return ContactHelper.getDisplayName(strUserName, contact);
			}
			return strOptionalNickName;
		}
		public static string getDisplayName(string username, Contact contact_0 = null)
		{
			if (username == null || username.get_Length() <= 0)
			{
				return "";
			}
			if (username == "fmessage")
			{
				return strings.Con_FMsg_TxtName;
			}
			if (username == "weixin")
			{
				return strings.Con_Plugin_Weixin;
			}
			if (username == "qmessage")
			{
				return strings.Con_Plugin_QQOfflineMsg_Nickname;
			}
			if (username == "floatbottle")
			{
				return strings.Contacts_Plugin_FloatBottle_Nickname;
			}
			if (username == "masssend")
			{
				return strings.Con_Plugin_MassSend_Nickname;
			}
			if (username == ConstantValue.TAG_BLOGAPP)
			{
				return strings.Contacts_Plugin_Blog;
			}
			if (username == ConstantValue.TAG_NEWS)
			{
				return strings.Plugin_news_title;
			}
			if (username == ConstantValue.TAG_QQMAIL)
			{
				return strings.Plugin_qqmail_title;
			}
			if (username == "filehelper")
			{
				return strings.WebMM_File_Transfer;
			}
			if (ContactHelper.isBottleContact(username))
			{
				return BContactMgr.getDisplayName(username);
			}
			Contact contact = contact_0 ?? StorageMgr.contact.method_0(username);
			if (contact != null)
			{
				return ContactHelper.GetContactDisplayName(contact);
			}
			if (ContactHelper.isQContact(username))
			{
				return ContactHelper.getQContactDisplayName(username);
			}
			if (ContactHelper.isWeixin(username) || ContactHelper.isChatRoom(username))
			{
				NetSceneBatchGetContact arg_112_0 = ServiceCenter.sceneBatchGetContact;
				List<string> list = new List<string>();
				list.Add(username);
				arg_112_0.doScene(list);
			}
			return username;
		}
		public static string getQContactDisplayName(string qConName)
		{
			List<string> list = new List<string>();
			list.Add(qConName);
			BatchGetContactProfileMgr.batchGetProfile(list);
			qConName = qConName.Substring(0, qConName.get_Length() - 5);
			uint nQQ = uint.Parse(qConName);
			QFriend qFriend = QFriendMgr.getQFriend(nQQ);
			if (qFriend != null)
			{
				qConName = QFriendMgr.getDisplayName(qFriend);
			}
			return qConName;
		}
		public static string GetContactDisplayName(Contact contact_0)
		{
			if (contact_0 == null)
			{
				return "";
			}
			if (ContactMgr.getUserType(contact_0.strUsrName) == ContactMgr.UserType.UserTypeChatRoom && !string.IsNullOrEmpty(contact_0.strNickName))
			{
				if (!(contact_0.strNickName == "群聊") && !(contact_0.strNickName == "聊天室") && !(contact_0.strNickName == "Group Chat"))
				{
					return contact_0.strNickName;
				}
				return strings.ChatDefaultTopic;
			}
			else
			{
				if (ToolFunction.checkIsLegalRemark(contact_0.strRemark))
				{
					return contact_0.strRemark;
				}
				if (!string.IsNullOrEmpty(contact_0.strNickName))
				{
					return contact_0.strNickName;
				}
				return contact_0.strUsrName;
			}
		}
		public static string getChatRoomStringInSession(string username, ref int int_0)
		{
			int_0 = 0;
			if (string.IsNullOrEmpty(username))
			{
				return "";
			}
			if (ContactMgr.getUserType(username) != ContactMgr.UserType.UserTypeChatRoom)
			{
				return "";
			}
			string chatRoomDisplayName = ContactHelper.getChatRoomDisplayName(username, ref int_0);
			string displayName = ContactHelper.getDisplayName(username, null);
			if (!(displayName == strings.ChatDefaultTopic) && !string.IsNullOrEmpty(displayName) && !(displayName == username))
			{
				return displayName;
			}
			if (string.IsNullOrEmpty(chatRoomDisplayName))
			{
				return displayName;
			}
			return chatRoomDisplayName;
		}
		public static string getChatRoomStringInChat(string username, ref int int_0)
		{
			int_0 = 0;
			if (string.IsNullOrEmpty(username))
			{
				return "";
			}
			if (ContactMgr.getUserType(username) != ContactMgr.UserType.UserTypeChatRoom)
			{
				return "";
			}
			ContactHelper.getChatRoomDisplayName(username, ref int_0);
			string displayName = ContactHelper.getDisplayName(username, null);
			if (!(displayName == strings.ChatDefaultTopic) && !string.IsNullOrEmpty(displayName) && !(displayName == username))
			{
				return displayName;
			}
			return strings.ChatDefaultTopic;
		}
		public static string getChatRoomDisplayName(List<Contact> currentRoomInfo)
		{
			if (currentRoomInfo != null && currentRoomInfo.get_Count() >= 1)
			{
				string text = "";
				using (List<Contact>.Enumerator enumerator = currentRoomInfo.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Contact current = enumerator.get_Current();
						if (text != "")
						{
							text = text + "," + ContactHelper.GetContactDisplayName(current);
						}
						else
						{
							text += ContactHelper.GetContactDisplayName(current);
						}
					}
				}
				return text;
			}
			return "";
		}
		public static string getChatRoomDisplayName(string username, ref int usernum)
		{
			if (username == null || username.get_Length() <= 0)
			{
				return "";
			}
			if (ContactMgr.getUserType(username) != ContactMgr.UserType.UserTypeChatRoom)
			{
				return "";
			}
			List<Contact> chatRoomMemberContactList = ChatRoomMgr.getChatRoomMemberContactList(username);
			if (chatRoomMemberContactList != null && chatRoomMemberContactList.get_Count() >= 1)
			{
				string text = "";
				using (List<Contact>.Enumerator enumerator = chatRoomMemberContactList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						Contact current = enumerator.get_Current();
						if (!(current.strUsrName == AccountMgr.curUserName))
						{
							if (text != "")
							{
								text = text + "," + ContactHelper.GetContactDisplayName(current);
							}
							else
							{
								text += ContactHelper.GetContactDisplayName(current);
							}
						}
					}
				}
				usernum = chatRoomMemberContactList.get_Count();
				return text;
			}
			return "";
		}
		private static bool isMicroBlogTencent(string username)
		{
			return username != null && username.get_Length() > 0 && username.EndsWith(ConstantValue.TAG_MICROBLOG_TENCENT);
		}
		public static bool isWeixin(string username)
		{
			return username != null && username.get_Length() > 0 && (!username.Contains("@") || username.EndsWith(ConstantValue.TAG_WEIXIN));
		}
		public static bool isChatRoom(string username)
		{
			return username != null && username.get_Length() > 0 && username.EndsWith(ConstantValue.TAG_CHATROOM);
		}
		public static bool isGroupCard(string username)
		{
			return username != null && username.get_Length() > 0 && username.EndsWith(ConstantValue.TAG_GROUPCARD);
		}
		public static bool isNeedShowChatEntry(Contact contact_0)
		{
			return contact_0 != null && !(contact_0.strUsrName == AccountMgr.strUsrName) && !(contact_0.strUsrName == "groupCardHeader@groupCardHeader") && !ToolFunction.systemPluginName.Contains(contact_0.strUsrName);
		}
		public static bool isNeedShowMenuHeader(Contact contact_0)
		{
			return contact_0 != null && !(contact_0.strUsrName == AccountMgr.strUsrName) && !(contact_0.strUsrName == "weixin") && !(contact_0.strUsrName == "groupCardHeader@groupCardHeader") && !ToolFunction.systemPluginNameCantDel.Contains(contact_0.strUsrName);
		}
		public static bool DeleteContact(Contact contact_0, bool bIsDelConv = true)
		{
			if (contact_0 == null)
			{
				return false;
			}
			if (bIsDelConv)
			{
				ConversationMgr.delConversation(contact_0.strUsrName);
			}
			ContactMgr.operationSetContact(contact_0, false);
			ServiceCenter.sceneNewSync.doScene(4, syncScene.MM_NEWSYNC_SCENE_OTHER);
			QFriendMgr.SetQFriendContact(contact_0.strUsrName, false);
			MobileContact byUserName = StorageMgr.mobileContact.getByUserName(contact_0.strUsrName);
			if (ChatContainerPage.getCuChatPageTalker() == contact_0.strUsrName)
			{
				ChatContainerPage.CloseChatPage();
			}
			if (byUserName != null)
			{
				MobileContactMgr.updatemContactToFriend(byUserName, false);
			}
			return true;
		}
		public static int GetContactStroke(Contact contact_0)
		{
			if (contact_0 == null)
			{
				return -1;
			}
			string text;
			if (!string.IsNullOrWhiteSpace(contact_0.strRemark))
			{
				text = contact_0.strRemark;
			}
			else
			{
				if (string.IsNullOrWhiteSpace(contact_0.strNickName))
				{
					return -1;
				}
				text = contact_0.strNickName;
			}
			if (ChineseHelper.IsChinese(text.get_Chars(0)))
			{
				int num = GetChineseStrokeCnt.GetCharStrokeCnt(text.get_Chars(0));
				if (num > 19)
				{
					num = 19;
				}
				return num;
			}
			return -1;
		}
		public static bool IsFavoriteContact(Contact contact_0)
		{
			return contact_0 != null && (contact_0.nFlags & 64u) != 0u;
		}
		public static List<Contact> GetConsFromBrandList(string strBrandList)
		{
			List<Contact> list = new List<Contact>();
			List<Contact> result;
			try
			{
				XDocument xDocument = XDocument.Parse(strBrandList);
				if (xDocument.get_Root().get_Name() != "brandlist")
				{
					Log.smethod_1("ContactHelper", "error object name=" + xDocument.get_Root().get_Name());
					result = null;
				}
				else
				{
					using (IEnumerator<XElement> enumerator = xDocument.get_Root().Elements().GetEnumerator())
					{
						while (enumerator.MoveNext())
						{
							XElement current = enumerator.get_Current();
							if (!current.get_IsEmpty() || current.get_HasAttributes())
							{
								list.Add(new Contact
								{
									strUsrName = (string)current.Element("username"),
									strNickName = (string)current.Element("nickname"),
									strAlias = (string)current.Element("alias"),
									strBrandIconURL = (string)current.Element("iconurl"),
									nFlags = (uint)current.Element("Hidden")
								});
							}
						}
					}
					result = list;
				}
			}
			catch (Exception ex)
			{
				Log.smethod_1("ContactHelper", "GetConsFromBrandList xml parse error=" + ex);
				result = null;
			}
			return result;
		}
		public static bool IsVerifiedContactVerified(Contact contact_0)
		{
			return contact_0 != null && (contact_0.nVerifyFlag & 16u) != 0u && !ToolFunction.checkIsStrSystemPlugin(contact_0.strUsrName);
		}
		public static bool IsVerifiedContact(Contact contact_0)
		{
			return contact_0 != null && contact_0.nVerifyFlag != 0u && !ToolFunction.checkIsStrSystemPlugin(contact_0.strUsrName);
		}
		public static bool IsGotoVerifiedProfile(Contact contact_0)
		{
			return ContactHelper.IsVerifiedContact(contact_0) && contact_0.strUsrName != "weixin";
		}
		public static bool IsVerifiedContact(string strUserName)
		{
			return ContactHelper.IsVerifiedContact(StorageMgr.contact.method_0(strUserName));
		}
	}
}
